home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Open Transport 1.3 / Open Transport SDK / Open Tpt Protocol Developer / Samples / Configurators / TMP_Config.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-30  |  7.2 KB  |  274 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TMP_Config.h
  3.  
  4.     Contains:    Template configuration structures
  5.  
  6.     To Do:
  7. */
  8.  
  9. #ifndef __TMP_CONFIG__
  10. #define __TMP_CONFIG__
  11.  
  12. #ifdef __cplusplus
  13.     #ifndef __OPENTPTPRIVETNEW__
  14.     #include <OpenTptPrivateNew.h>
  15.     #endif
  16. #endif
  17. #ifndef __OPENTPTCLIENT__
  18. #include <OpenTptClient.h>
  19. #endif
  20. #ifndef __STROPTS__
  21. #include <stropts.h>
  22. #endif
  23.  
  24. #if GENERATING68K
  25.     #define TMPCONFIG_USES_CFM    0
  26.     #define TMPCONFIG_USES_ASLM    1
  27. #else
  28.     #define TMPCONFIG_USES_CFM    1
  29.     #define TMPCONFIG_USES_ASLM    0
  30. #endif
  31.  
  32. /*******************************************************************************
  33. ** Some constants
  34. **
  35. ** You need to change these IDs!!!
  36. ** We use the name "configurator" for the resident portion of your configurator,
  37. ** and the name "controller" for non-resident portion that is loaded into 
  38. ** memory when someone uses your protocol or driver.
  39. ********************************************************************************/
  40.  
  41. #define kMyEvent1                kPRIVATEEVENT + 1
  42. #define kMyEvent2                kPRIVATEEVENT + 2
  43. #define kMyNoClientEvent        kPRIVATEEVENT + 3
  44.  
  45. #define kMyResourceID            128            /* Our STR# resource                */
  46. #define kEvent1ID                1            /* Index for event in STR# resource */
  47. #define kEvent2ID                2
  48.  
  49. /*
  50.  * These are the IDs we need to use when we first plumb a stream (i.e. we
  51.  * have nothing to clone yet.
  52.  */
  53. #define kTMPCreateConfigASLMID        kOTClientPrefix "TMPCreateCfig"
  54. #define kTMPCreateConfigCFMID        "OTTMPConfigCreateLib"
  55. /*
  56.  * This is the ID of the resident code
  57.  */
  58. #define kTMPRSConfigASLMID            kOTClientPrefix "TMPCfigor"
  59. #define kTMPRSConfigCFMD            "OTTMPConfigurator"
  60. /*
  61.  * This is the ID of the non-resident code
  62.  */
  63. #define kTMPConfigASLMID            kOTClientPrefix "TMPCntrlr"
  64. #define kTMPConfigCFMMID            "OTTMPController"
  65. /*
  66.  * Timeout to unload
  67.  */
  68. enum
  69. {
  70.     kMyUnloadTimeout = 5 * 1000
  71. };
  72.  
  73. /*
  74.  * MIOC_CFIG is the IOCTL base used to send configuration data to yourself.  You
  75.  * don't have to use it - you can use transparent IOCTLs, but this is more
  76.  * convenient.
  77.  */
  78. enum
  79. {
  80.     kMyConfigureIoctl    = MIOC_CMD(MIOC_CFIG, 0)
  81. };
  82.  
  83. /*******************************************************************************
  84. ** Some Structures
  85. ********************************************************************************/
  86.  
  87. struct AConfiguration;
  88.  
  89. #if PRAGMA_ALIGN_SUPPORTED
  90. #pragma options align=mac68k
  91. #endif
  92.  
  93. /*
  94.  * This structure is what we use when we create a state machine.
  95.  * It includes all the extra information we need in order to plumb
  96.  * the link or protocol.
  97.  */
  98. typedef struct TMPOpenInfo        TMPOpenInfo;
  99. typedef struct AConfiguration    AConfiguration;
  100.  
  101. struct TMPOpenInfo
  102. {
  103.     OTLink                    fLink;
  104.     AConfiguration*            fConfig;        /* Our configuration structure            */
  105.     OTStateMachine*            fStateMachine;    /* The state machine we're using        */
  106.     StreamRef                fTheStream;        /* The current stream being worked on     */
  107.     OTNotifyProcPtr            fNotifyProc;    /* So we can install the right function    */
  108.     OTConfiguration*        fCfig;            /* Configuration we're creating            */
  109.     OTConfiguration*        fToPush;        /* Configuration to push                */
  110.     struct strioctl            fIoctlInfo;        /* A place for I_STR Ioctls to have        */
  111.     OTOpenFlags                fOpenFlags;        /* The original Open flags                */
  112.     OSErr                    fSavedError;    /* Place to save error as we unwind        */
  113. #if TMPCONFIG_USES_CFM
  114.     UInt32                    fCreateID;        /* CFM ID, if needed                    */
  115. #endif
  116. };
  117.  
  118. typedef struct MySharedStruct    MySharedStruct;
  119.  
  120. #ifdef __cplusplus
  121. extern "C" {
  122. #endif
  123.  
  124.     typedef void        (*UnloadSelfProcPtr)(void);
  125.     typedef OSStatus    (*CreateMyConfigProcPtr)(MySharedStruct*);
  126.     
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130.  
  131. /*
  132.  * This structure is shared between our "controller" and our "configurator".
  133.  */
  134. struct MySharedStruct
  135. {
  136.     UnloadSelfProcPtr        scheduleUnloadProc;        /* Procedure to schedule unload    */
  137.     OTProcessProcPtr        unloadProc;                /* Procedure to do unload Now    */
  138.     TOTConfigurator*        cfig;                    /* The configurator                */
  139.     long                    systemTask;                /* System task for unloading    */
  140. };
  141.  
  142. /*******************************************************************************
  143. ** Preferences (if applicable)
  144. ********************************************************************************/
  145.  
  146. enum
  147. {
  148.     kTMPPrefsVersion    = 1,
  149.     kTMPNumPrefs        = 3
  150. };
  151.  
  152. struct MyPreferences
  153. {
  154.     UInt16            fVersion;
  155.     UInt16            fNumPrefs;
  156.     OTPortRef        fPort;
  157.     OTLink            fLink;
  158.     void*            fPrefs[kTMPNumPrefs];
  159. };
  160.  
  161. typedef struct MyPreferences    MyPreferences;
  162.  
  163. struct Prot1Prefs
  164. {
  165.     UInt16        fVersion;
  166.     UInt16        fSize;
  167.     UInt32        fMyAddress;
  168.     Boolean        fIsFixed;
  169. };
  170.  
  171. typedef struct Prot1Prefs    Prot1Prefs;
  172.  
  173. struct Prot2Prefs
  174. {
  175.     UInt16        fVersion;
  176.     UInt16        fSize;
  177.     OTTimeout    fDefaultTimeout;
  178. };
  179.  
  180. typedef struct Prot2Prefs    Prot2Prefs;
  181.  
  182. struct Prot3Prefs
  183. {
  184.     UInt16        fVersion;
  185.     UInt16        fSize;
  186.     UInt32        fRetryCount;
  187.     OTTimeout    fRetryTimeout;
  188. };
  189.  
  190. typedef struct Prot3Prefs    Prot3Prefs;
  191.  
  192. /*******************************************************************************
  193. ** Struct AConfiguration
  194. ********************************************************************************/
  195.  
  196. enum
  197. {
  198.     kIsBeingCreated    = 0,            /* Currently creating configuration            */
  199.     kIsUnused        = 1,            /* Configuration is currently unused        */
  200.     kIsScheduled    = 2,            /* Configuration is scheduled for unload    */
  201.     kIsInUse        = 3                /* Configuration is in use                    */
  202. };
  203.  
  204. struct AConfiguration
  205. {
  206.     OTLink                    fMyLink;            /* To link configurations together                */
  207.     StreamRef                fCtlStream;            /* The control stream                            */
  208.     StreamRef                fHelperStream;        /* The stream with our helper module on it        */
  209.     OTPortRef                fLinkID;            /* The portref of this stream                    */
  210.     OTPortRef                fOurID;                /* The portref of our network layer                */
  211.     long                    fTimerTask;            /* A timer task to use with this config            */
  212.     long                    fSystemTask;        /* A system task to use with this config        */
  213.                                                 /* Name of a helper module we had to register    */
  214.                                                 /* as part of our plumbing                        */
  215.     MyPreferences*            fPrefs;                /* Pointer to our prefs structure                */
  216.     char                    fNetworkName[kMaxModuleNameSize];
  217.     UInt8                    fStatus;            /* Status variable so we know where we are        */
  218. };
  219.  
  220. /*******************************************************************************
  221. ** MyGlobal structure
  222. ********************************************************************************/
  223.  
  224. struct MyGlobal
  225. {
  226.     OTList                fConfigs;                /* List of configurations        */
  227.     UInt32                fMyMask;
  228. }; 
  229.  
  230. typedef struct MyGlobal    MyGlobal;
  231.  
  232. /*******************************************************************************
  233. ** CLASS TMyConfigurator
  234. ********************************************************************************/
  235.  
  236. /*
  237.  * This enum is gives the "index number" of the protocols that we support
  238.  */
  239.  
  240. enum
  241. {
  242.     kProt1ID = 0,
  243.     kProt2ID, kProt3ID
  244. };
  245.  
  246. enum
  247. {
  248.     kProt1PrefsIndex = 1, kProt2PrefsIndex, kProt3PrefsIndex
  249. };
  250.  
  251. /*
  252.  * This defines the list of protocols we support, in the same order
  253.  * as the enum above.
  254.  */
  255. #define kProtocolList    "Prot1", "Prot2", "Prot3"
  256.  
  257. struct TMPConfigurator
  258. {
  259.     MyGlobal*            fGlobal;                /* Pointer to my global variables list        */
  260.     MySharedStruct*        fShared;                /* Pointer to the shared structure            */
  261.     TMPOpenInfo*        fList;                    /* List of outstanding open requests        */
  262.     OTGate                fGate;                    /* Gate to synchronize stream opening        */
  263.     Boolean                fDontUnload;            /* Boolean to tell us to not unload            */
  264.     Boolean                fShuttingDown;            /* Flag that we're shutting down            */
  265. };
  266.  
  267. typedef struct TMPConfigurator    TMPConfigurator;
  268.  
  269. #if PRAGMA_ALIGN_SUPPORTED
  270. #pragma options align=reset
  271. #endif
  272.  
  273. #endif
  274.